package com.ruoyi.pay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.pay.domain.MchApp;
import com.ruoyi.pay.mapper.MchAppMapper;
import com.ruoyi.pay.service.MchAppService;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商户应用表 服务实现类
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2021-06-15
 */
@RequiredArgsConstructor
@Service
public class MchAppServiceImpl implements MchAppService {

    private final MchAppMapper baseMapper;

    public TableDataInfo<MchApp> selectPage(PageQuery pageQuery, MchApp mchApp) {

        LambdaQueryWrapper<MchApp> wrapper = MchApp.gw();
        if (StringUtils.isNotBlank(mchApp.getMchNo())) {
            wrapper.eq(MchApp::getMchNo, mchApp.getMchNo());
        }
        if (StringUtils.isNotEmpty(mchApp.getAppId())) {
            wrapper.eq(MchApp::getAppId, mchApp.getAppId());
        }
        if (StringUtils.isNotEmpty(mchApp.getAppName())) {
            wrapper.eq(MchApp::getAppName, mchApp.getAppName());
        }
        if (mchApp.getState() != null) {
            wrapper.eq(MchApp::getState, mchApp.getState());
        }
        wrapper.orderByDesc(MchApp::getCreateBy);

        Page<MchApp> page = baseMapper.selectPage(pageQuery.build(), wrapper);
        return TableDataInfo.build(page);
    }


    public MchApp getOneByMch(String mchNo, String appId){
        return baseMapper.selectOne(MchApp.gw().eq(MchApp::getMchNo, mchNo).eq(MchApp::getAppId, appId));
    }

    @Override
    public MchApp getById( String id) {
        return baseMapper.selectById(id);
    }


}
